
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>基础 · 千锋大前端小册-webpack</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="古艺散人">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-insert-logo/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    

        
    
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="01-Webpack基础.html" />
    
    
    <link rel="prev" href="../" />
    

    
        <link rel="shortcut icon" href='../source/images/favicon.jpg' type="image/x-icon">
    
    
        <link rel="bookmark" href='../source/images/favicon.jpg' type="image/x-icon">
    
    
        <link rel="apple-touch-icon" href='../source/images/apple-touch-icon.jpg'>
    
    
        
        <link rel="apple-touch-icon" sizes="120x120" href="../source/images/apple-touch-icon.jpg">
        
        <link rel="apple-touch-icon" sizes="180x180" href="../source/images/apple-touch-icon.jpg">
        
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"buttons":[{"user":"lurongtao","repo":"felixbooks-electron","type":"star","size":"small","count":true}]};
    </script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2" data-path="01-Webpack基础.html">
            
                <a href="01-Webpack基础.html">
            
                    
                    基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.2.1" data-path="01-Webpack基础.html">
            
                <a href="01-Webpack基础.html">
            
                    
                    01-Webpack基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../advanced/01-tree-shaking.html">
            
                <a href="../advanced/01-tree-shaking.html">
            
                    
                    高级
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../advanced/01-tree-shaking.html">
            
                <a href="../advanced/01-tree-shaking.html">
            
                    
                    01-TreeShaking
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../advanced/02-development-production.html">
            
                <a href="../advanced/02-development-production.html">
            
                    
                    02-development&production
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../advanced/03-code-splitting.html">
            
                <a href="../advanced/03-code-splitting.html">
            
                    
                    03-Code Splitting
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../advanced/04-lazy-loading.html">
            
                <a href="../advanced/04-lazy-loading.html">
            
                    
                    04-模块懒加载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../advanced/05-prefetch.html">
            
                <a href="../advanced/05-prefetch.html">
            
                    
                    05-代码利用率
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../advanced/06-webpack优化.html">
            
                <a href="../advanced/06-webpack优化.html">
            
                    
                    06-webpack优化
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../thanks/">
            
                <a href="../thanks/">
            
                    
                    感谢
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >基础</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#webpack-&#x57FA;&#x7840;"><b></b>Webpack &#x57FA;&#x7840;</a></li><ul><ul><li><span class="title-icon "></span><a href="#&#x4E00;&#x3001;babel73--&#x4E2D;-babelpreset-env-&#x7684;&#x4F7F;&#x7528;"><b></b>&#x4E00;&#x3001;Babel7.3- &#x4E2D; @babel/preset-env &#x7684;&#x4F7F;&#x7528;</a></li><li><span class="title-icon "></span><a href="#&#x4E8C;&#x3001;-babel74-&#x4E2D;-babelpreset-env-&#x7684;&#x4F7F;&#x7528;"><b></b>&#x4E8C;&#x3001; babel7.4 &#x4E2D; @babel/preset-env &#x7684;&#x4F7F;&#x7528;</a></li></ul></ul></ul></div><a href="#webpack-&#x57FA;&#x7840;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="webpack-&#x57FA;&#x7840;"><a name="webpack-&#x57FA;&#x7840;" class="anchor-navigation-ex-anchor" href="#webpack-&#x57FA;&#x7840;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="webpack-&#x57FA;&#x7840;" class="plugin-anchor" href="#webpack-&#x57FA;&#x7840;"><i class="fa fa-link" aria-hidden="true"></i></a>Webpack &#x57FA;&#x7840;</h1>
<p>&#x4EE5;&#x4E0B;&#x57FA;&#x672C;&#x914D;&#x7F6E;&#x6CA1;&#x6709;&#x5C55;&#x5F00;&#x6765;&#x8BB2;&#x89E3;&#xFF0C;&#x4EE5;&#x540E;&#x8865;&#x5145;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;path&apos;</span>)

<span class="hljs-keyword">const</span> HtmlWebpackPlugin = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;html-webpack-plugin&apos;</span>)
<span class="hljs-keyword">const</span> MiniCssExtractPlugin = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;mini-css-extract-plugin&apos;</span>)

<span class="hljs-keyword">const</span> VueLoaderPlugin = <span class="hljs-built_in">require</span>(<span class="hljs-string">&apos;vue-loader/lib/plugin&apos;</span>)

<span class="hljs-built_in">module</span>.exports = {
  mode: <span class="hljs-string">&apos;development&apos;</span>,

  entry: {
    <span class="hljs-string">&apos;scripts/app&apos;</span>: <span class="hljs-string">&apos;./src/scripts/app.js&apos;</span>,
    <span class="hljs-comment">// &apos;scripts/app&apos;: [&quot;@babel/polyfill&quot;, &quot;./src/scripts/app.js&quot;],</span>
    <span class="hljs-string">&apos;scripts/index&apos;</span>: <span class="hljs-string">&apos;./src/scripts/index.js&apos;</span>
  },

  output: {
    path: path.resolve(__dirname, <span class="hljs-string">&apos;../dist&apos;</span>),
    publicPath: <span class="hljs-string">&apos;http://localhost:9000/&apos;</span>,
    filename: <span class="hljs-string">&apos;[name].js&apos;</span>
  },

  devtool: <span class="hljs-string">&apos;inline-source-map&apos;</span>,

  resolve: {
    alias: {
      <span class="hljs-string">&apos;@&apos;</span>: path.resolve(__dirname, <span class="hljs-string">&apos;../component&apos;</span>)
    },

    extensions: [<span class="hljs-string">&quot;.js&quot;</span>, <span class="hljs-string">&quot;.json&quot;</span>, <span class="hljs-string">&quot;.jsx&quot;</span>]
  },

  <span class="hljs-built_in">module</span>: {
    rules: [
      {
        test: <span class="hljs-regexp">/\.vue$/</span>,
        loader: <span class="hljs-string">&apos;vue-loader&apos;</span>,
        options: {
          extractCSS: <span class="hljs-literal">true</span>
        }
      },
      {
        test: <span class="hljs-regexp">/\.m?jsx?$/</span>,
        exclude: <span class="hljs-regexp">/(node_modules|bower_components)/</span>,
        use: {
          loader: <span class="hljs-string">&apos;babel-loader&apos;</span>,
          options: {
            <span class="hljs-string">&quot;presets&quot;</span>: [
              [
                <span class="hljs-string">&quot;@babel/preset-env&quot;</span>,
                <span class="hljs-comment">// babel 7.3</span>
                <span class="hljs-comment">// {</span>
                <span class="hljs-comment">//   &quot;targets&quot;: {</span>
                <span class="hljs-comment">//     &quot;chrome&quot;: &quot;58&quot;,</span>
                <span class="hljs-comment">//     &quot;ie&quot;: &quot;11&quot;</span>
                <span class="hljs-comment">//   },</span>
                <span class="hljs-comment">//   &quot;useBuiltIns&quot;: &quot;usage&quot;</span>
                <span class="hljs-comment">// }</span>

                <span class="hljs-comment">// babel 7.4</span>
                {
                  useBuiltIns: <span class="hljs-string">&quot;entry&quot;</span>, <span class="hljs-comment">// or &quot;usage&quot;</span>
                  corejs: <span class="hljs-number">3</span>,
                }
              ],
              <span class="hljs-string">&quot;@babel/preset-react&quot;</span>
            ],
            <span class="hljs-string">&quot;plugins&quot;</span>: [
              [<span class="hljs-string">&quot;@babel/plugin-proposal-decorators&quot;</span>, { <span class="hljs-string">&quot;legacy&quot;</span>: <span class="hljs-literal">true</span> }],
              [<span class="hljs-string">&quot;@babel/plugin-proposal-class-properties&quot;</span>, { <span class="hljs-string">&quot;loose&quot;</span>: <span class="hljs-literal">true</span> }]
            ]
          }
        }
      },
      {
        test: <span class="hljs-regexp">/\.s?css$/</span>,
        use: [
          {
            loader: MiniCssExtractPlugin.loader,
            options: {
              hmr: process.env.NODE_ENV === <span class="hljs-string">&apos;development&apos;</span>,
            },
          }, 

          {
            loader: <span class="hljs-string">&quot;css-loader&quot;</span>
          }, 
          {
            loader: <span class="hljs-string">&quot;postcss-loader&quot;</span>,
            options: { 
              ident: <span class="hljs-string">&quot;postcss&quot;</span>, 
              plugins: () =&gt; [<span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;postcss-preset-env&quot;</span>)()]
            }
          },
          {
            loader: <span class="hljs-string">&quot;sass-loader&quot;</span>
          }
        ]
      },
      {
        test: <span class="hljs-regexp">/\.(jpg|jpeg|png|gif)$/</span>,
        use: [
          {
            loader: <span class="hljs-string">&apos;url-loader&apos;</span>,
            options: {
              limit: <span class="hljs-number">800</span>,
              name: <span class="hljs-string">&apos;[name]-[hash:6].[ext]&apos;</span>,
              outputPath: <span class="hljs-string">&apos;images/&apos;</span>
            }
          }
        ]
      }
    ]
  },

  plugins: [
    <span class="hljs-keyword">new</span> HtmlWebpackPlugin({
      title: <span class="hljs-string">&apos;webpack demo&apos;</span>,
      filename: <span class="hljs-string">&apos;index.html&apos;</span>,
      template: <span class="hljs-string">&apos;./src/index.ejs&apos;</span>,
    }),

    <span class="hljs-keyword">new</span> MiniCssExtractPlugin({
      moduleFilename: ({ name }) =&gt; <span class="hljs-string">`<span class="hljs-subst">${name.replace(&apos;scripts&apos;, &apos;styles&apos;)}</span>-[hash:6].css`</span>,
      ignoreOrder: <span class="hljs-literal">false</span>,
    }),

    <span class="hljs-keyword">new</span> VueLoaderPlugin()
  ],

  devServer: {
    contentBase: <span class="hljs-string">&apos;./dist&apos;</span>,
    compress: <span class="hljs-literal">true</span>,
    port: <span class="hljs-number">9000</span>
  }
}
</code></pre>
<h3 id="&#x4E00;&#x3001;babel73--&#x4E2D;-babelpreset-env-&#x7684;&#x4F7F;&#x7528;"><a name="&#x4E00;&#x3001;babel73--&#x4E2D;-babelpreset-env-&#x7684;&#x4F7F;&#x7528;" class="anchor-navigation-ex-anchor" href="#&#x4E00;&#x3001;babel73--&#x4E2D;-babelpreset-env-&#x7684;&#x4F7F;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x4E00;&#x3001;babel73--&#x4E2D;-babelpreset-env-&#x7684;&#x4F7F;&#x7528;" class="plugin-anchor" href="#&#x4E00;&#x3001;babel73--&#x4E2D;-babelpreset-env-&#x7684;&#x4F7F;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E00;&#x3001;Babel7.3- &#x4E2D; @babel/preset-env &#x7684;&#x4F7F;&#x7528;</h3>
<h5 id="1&#x3001;-&#x57FA;&#x672C;&#x7528;&#x6CD5;&#x4ECB;&#x7ECD;"><a name="1&#x3001;-&#x57FA;&#x672C;&#x7528;&#x6CD5;&#x4ECB;&#x7ECD;" class="anchor-navigation-ex-anchor" href="#1&#x3001;-&#x57FA;&#x672C;&#x7528;&#x6CD5;&#x4ECB;&#x7ECD;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="1&#x3001;-&#x57FA;&#x672C;&#x7528;&#x6CD5;&#x4ECB;&#x7ECD;" class="plugin-anchor" href="#1&#x3001;-&#x57FA;&#x672C;&#x7528;&#x6CD5;&#x4ECB;&#x7ECD;"><i class="fa fa-link" aria-hidden="true"></i></a>1&#x3001; &#x57FA;&#x672C;&#x7528;&#x6CD5;&#x4ECB;&#x7ECD;</h5>
<p>&#x662F;&#x4E00;&#x7CFB;&#x5217;&#x63D2;&#x4EF6;&#x7684;&#x96C6;&#x5408;&#xFF0C;&#x5305;&#x542B;&#x4E86;&#x6211;&#x4EEC;&#x5728;babel6&#x4E2D;&#x5E38;&#x7528;&#x7684;es2015,es2016, es2017&#x7B49;&#x6700;&#x65B0;&#x7684;&#x8BED;&#x6CD5;&#x8F6C;&#x5316;&#x63D2;&#x4EF6;&#xFF0C;&#x5141;&#x8BB8;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x6700;&#x65B0;&#x7684;js&#x8BED;&#x6CD5;&#xFF0C;&#x6BD4;&#x5982; let&#xFF0C;const&#xFF0C;&#x7BAD;&#x5934;&#x51FD;&#x6570;&#x7B49;&#x7B49;&#xFF0C;&#x4F46;&#x4E0D;&#x5305;&#x62EC;stage-x&#x9636;&#x6BB5;&#x7684;&#x63D2;&#x4EF6;&#x3002;</p>
<h5 id="2&#x3001;-babelpolyfill"><a name="2&#x3001;-babelpolyfill" class="anchor-navigation-ex-anchor" href="#2&#x3001;-babelpolyfill"><i class="fa fa-link" aria-hidden="true"></i></a><a name="2&#x3001;-babelpolyfill" class="plugin-anchor" href="#2&#x3001;-babelpolyfill"><i class="fa fa-link" aria-hidden="true"></i></a>2&#x3001; @babel/polyfill</h5>
<p>&#x4E5F;&#x5C31;&#x662F; babel6 &#x4E2D;&#x7684; babel-polyfill , &#x4F7F;&#x7528; preset-env &#x80FD;&#x5C06;&#x6700;&#x65B0;&#x7684;&#x8BED;&#x6CD5;&#x8F6C;&#x6362;&#x4E3A;ecmascript5&#x7684;&#x5199;&#x6CD5;&#xFF0C;&#x5F53;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x65B0;&#x589E;&#x7684;&#x5168;&#x5C40;&#x51FD;&#x6570;(&#x6BD4;&#x5982;promise, Array.from)&#x548C;&#x5B9E;&#x4F8B;&#x65B9;&#x6CD5;(&#x6BD4;&#x5982; Array.prototype.includes )&#x65F6;&#x5C31;&#x9700;&#x8981;&#x5F15;&#x5165; polyfill &#xFF0C;&#x4E00;&#x822C;&#x7528;&#x6CD5; &#x5728; index.js&#x6587;&#x4EF6;&#x7684;&#x6700;&#x4E0A;&#x5C42;&#x5F15;&#x5165;&#xFF0C;&#x6216;&#x662F;&#x5728;&#x6253;&#x5305;&#x6587;&#x4EF6;&#x7684;entry &#x5165;&#x53E3;&#x5904;&#x5F15;&#x5165;&#xFF0C;&#x8FD9;&#x6837;&#x505A;&#x7684;&#x7F3A;&#x70B9;&#x662F;&#x4F1A;&#x5168;&#x5C40;&#x5F15;&#x5165;&#x6574;&#x4E2A; polyfill&#x5305;&#xFF0C;&#x6BD4;&#x5982;promise &#x4F1A;&#x5168;&#x5C40;&#x5F15;&#x5165;&#xFF0C;&#x6C61;&#x67D3;&#x5168;&#x5C40;&#x73AF;&#x5883;&#x3002;</p>
<h5 id="3&#x3001;-babelpolyfill-&#x548C;-babelpreset-env-&#x7684;&#x5173;&#x7CFB;"><a name="3&#x3001;-babelpolyfill-&#x548C;-babelpreset-env-&#x7684;&#x5173;&#x7CFB;" class="anchor-navigation-ex-anchor" href="#3&#x3001;-babelpolyfill-&#x548C;-babelpreset-env-&#x7684;&#x5173;&#x7CFB;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="3&#x3001;-babelpolyfill-&#x548C;-babelpreset-env-&#x7684;&#x5173;&#x7CFB;" class="plugin-anchor" href="#3&#x3001;-babelpolyfill-&#x548C;-babelpreset-env-&#x7684;&#x5173;&#x7CFB;"><i class="fa fa-link" aria-hidden="true"></i></a>3&#x3001; @babel/polyfill &#x548C; @babel/preset-env &#x7684;&#x5173;&#x7CFB;</h5>
<p>@babel/preset-env &#x4E2D;&#x4E0E; @babel/polyfill &#x7684;&#x76F8;&#x5173;&#x53C2;&#x6570;&#x6709; targets &#x548C; useBuiltIns &#x4E24;&#x4E2A;</p>
<p><strong>targets: &#x652F;&#x6301;&#x7684;&#x76EE;&#x6807;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x5217;&#x8868;</strong></p>
<pre><code class="lang-json"><span class="hljs-string">&quot;targets&quot;</span>: {
  <span class="hljs-string">&quot;chrome&quot;</span>: <span class="hljs-string">&quot;58&quot;</span>,
  <span class="hljs-string">&quot;ie&quot;</span>: <span class="hljs-string">&quot;11&quot;</span>
}
</code></pre>
<p><strong>useBuiltIns: &#x53C2;&#x6570;&#x6709; &#x201C;entry&#x201D;&#x3001;&#x201D;usage&#x201D;&#x3001;false &#x4E09;&#x4E2A;&#x503C;</strong></p>
<p>&#x9ED8;&#x8BA4;&#x503C;&#x662F;false&#xFF0C;&#x6B64;&#x53C2;&#x6570;&#x51B3;&#x5B9A;&#x4E86;babel&#x6253;&#x5305;&#x65F6;&#x5982;&#x4F55;&#x5904;&#x7406;@babel/polyfilll &#x8BED;&#x53E5;&#x3002;</p>
<p>&#x201C;entry&#x201D;: &#x4F1A;&#x5C06;&#x6587;&#x4EF6;&#x4E2D; <code>import @babel/polyfilll</code> &#x8BED;&#x53E5; &#x7ED3;&#x5408; targets &#xFF0C;&#x8F6C;&#x6362;&#x4E3A;&#x4E00;&#x7CFB;&#x5217;&#x5F15;&#x5165;&#x8BED;&#x53E5;&#xFF0C;&#x53BB;&#x6389;&#x76EE;&#x6807;&#x6D4F;&#x89C8;&#x5668;&#x5DF2;&#x652F;&#x6301;&#x7684; polyfilll &#x6A21;&#x5757;&#xFF0C;&#x4E0D;&#x7BA1;&#x4EE3;&#x7801;&#x91CC;&#x6709;&#x6CA1;&#x6709;&#x7528;&#x5230;&#xFF0C;&#x53EA;&#x8981;&#x76EE;&#x6807;&#x6D4F;&#x89C8;&#x5668;&#x4E0D;&#x652F;&#x6301;&#x90FD;&#x4F1A;&#x5F15;&#x5165;&#x5BF9;&#x5E94;&#x7684; polyfilll &#x6A21;&#x5757;&#x3002;</p>
<p>&#x201C;usage&#x201D;: &#x4E0D;&#x9700;&#x8981;&#x624B;&#x52A8;&#x5728;&#x4EE3;&#x7801;&#x91CC;&#x5199; <code>import @babel/polyfilll</code>&#xFF0C;&#x6253;&#x5305;&#x65F6;&#x4F1A;&#x81EA;&#x52A8;&#x6839;&#x636E;&#x5B9E;&#x9645;&#x4EE3;&#x7801;&#x7684;&#x4F7F;&#x7528;&#x60C5;&#x51B5;&#xFF0C;&#x7ED3;&#x5408; targets &#x5F15;&#x5165;&#x4EE3;&#x7801;&#x91CC;&#x5B9E;&#x9645;&#x7528;&#x5230;&#x90E8;&#x5206; polyfilll &#x6A21;&#x5757;</p>
<p>false: &#x5BF9; import&#x2018;@babel/polyfilll&#x2019;&#x4E0D;&#x4F5C;&#x4EFB;&#x4F55;&#x5904;&#x7406;&#xFF0C;&#x4E5F;&#x4E0D;&#x4F1A;&#x81EA;&#x52A8;&#x5F15;&#x5165; polyfilll &#x6A21;&#x5757;&#x3002;</p>
<p>&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#x5728; webpack &#x6253;&#x5305;&#x6587;&#x4EF6;&#x914D;&#x7F6E;&#x7684; entry &#x4E2D;&#x5F15;&#x5165;&#x7684; @babel/polyfill &#x4E0D;&#x4F1A;&#x6839;&#x636E; useBuiltIns &#x914D;&#x7F6E;&#x4EFB;&#x4F55;&#x8F6C;&#x6362;&#x5904;&#x7406;&#x3002;</p>
<h5 id="&#x603B;&#x7ED3;&#xFF1A;"><a name="&#x603B;&#x7ED3;&#xFF1A;" class="anchor-navigation-ex-anchor" href="#&#x603B;&#x7ED3;&#xFF1A;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x603B;&#x7ED3;&#xFF1A;" class="plugin-anchor" href="#&#x603B;&#x7ED3;&#xFF1A;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x603B;&#x7ED3;&#xFF1A;</h5>
<p>&#x5728;&#x4E1A;&#x52A1;&#x9879;&#x76EE;&#x4E2D;&#x9700;&#x8981;&#x7528;&#x5230;polyfill&#x65F6;, &#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x548C; @babel/preset-env &#x7684; targets &#x548C; useBuiltIns: usage &#x6765;&#x6839;&#x636E;&#x76EE;&#x6807;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x652F;&#x6301;&#x60C5;&#x51B5;&#xFF0C;&#x6309;&#x9700;&#x5F15;&#x5165;&#x7528;&#x5230;&#x7684; polyfill &#x6587;&#x4EF6;&#x3002;</p>
<p>&#x4E0D;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528; <code>import @babel/polyfilll</code> &#x4E00;&#x6B21;&#x6027;&#x5F15;&#x5165;&#x6240;&#x6709;&#x7684; polyfill &#x6587;&#x4EF6;&#x3002;</p>
<h3 id="&#x4E8C;&#x3001;-babel74-&#x4E2D;-babelpreset-env-&#x7684;&#x4F7F;&#x7528;"><a name="&#x4E8C;&#x3001;-babel74-&#x4E2D;-babelpreset-env-&#x7684;&#x4F7F;&#x7528;" class="anchor-navigation-ex-anchor" href="#&#x4E8C;&#x3001;-babel74-&#x4E2D;-babelpreset-env-&#x7684;&#x4F7F;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x4E8C;&#x3001;-babel74-&#x4E2D;-babelpreset-env-&#x7684;&#x4F7F;&#x7528;" class="plugin-anchor" href="#&#x4E8C;&#x3001;-babel74-&#x4E2D;-babelpreset-env-&#x7684;&#x4F7F;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E8C;&#x3001; babel7.4 &#x4E2D; @babel/preset-env &#x7684;&#x4F7F;&#x7528;</h3>
<h5 id="core-js&#x4ECB;&#x7ECD;"><a name="core-js&#x4ECB;&#x7ECD;" class="anchor-navigation-ex-anchor" href="#core-js&#x4ECB;&#x7ECD;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="core-js&#x4ECB;&#x7ECD;" class="plugin-anchor" href="#core-js&#x4ECB;&#x7ECD;"><i class="fa fa-link" aria-hidden="true"></i></a>core-js&#x4ECB;&#x7ECD;</h5>
<p>&#x5176;&#x5B9E;core-js&#x662F;&#x6211;&#x4EEC;&#x80FD;&#x591F;&#x4F7F;&#x7528;&#x65B0;&#x7684;API&#x7684;&#x6700;&#x91CD;&#x8981;&#x7684;&#x5305;&#xFF0C;&#x7136;&#x800C;&#x4E00;&#x822C;&#x60C5;&#x51B5;&#x5B83;&#x9690;&#x85CF;&#x5728;webpack&#x7F16;&#x8BD1;&#x540E;&#x7684;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x4E00;&#x822C;&#x4E0D;&#x4F1A;&#x53BB;&#x67E5;&#x770B;&#xFF0C;&#x6240;&#x4EE5;&#x5BB9;&#x6613;&#x88AB;&#x9057;&#x5FD8;&#xFF0C;&#x6211;&#x4EEC;&#x5728;webpack&#x751F;&#x6210;&#x73AF;&#x5883;&#x4E0B;&#xFF0C;&#x67E5;&#x770B;&#x7F16;&#x8BD1;&#x540E;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x4F8B;&#x5982;includes&#x5C31;&#x662F;&#x4ECE;core-js&#x5BFC;&#x51FA;&#x5230;&#x6211;&#x4EEC;&#x7684;&#x4EE3;&#x7801;&#x53BB;&#x7684;&#x3002;</p>
<p><img src="https://s2.ax1x.com/2019/10/07/uR9QE9.png" alt="img"></p>
<h5 id="core-js&#x662F;&#x4EC0;&#x4E48;"><a name="core-js&#x662F;&#x4EC0;&#x4E48;" class="anchor-navigation-ex-anchor" href="#core-js&#x662F;&#x4EC0;&#x4E48;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="core-js&#x662F;&#x4EC0;&#x4E48;" class="plugin-anchor" href="#core-js&#x662F;&#x4EC0;&#x4E48;"><i class="fa fa-link" aria-hidden="true"></i></a>core-js&#x662F;&#x4EC0;&#x4E48;</h5>
<ul>
<li>&#x5B83;&#x662F;JavaScript&#x6807;&#x51C6;&#x5E93;&#x7684;polyfill</li>
<li>&#x5B83;&#x5C3D;&#x53EF;&#x80FD;&#x7684;&#x8FDB;&#x884C;&#x6A21;&#x5757;&#x5316;&#xFF0C;&#x8BA9;&#x4F60;&#x80FD;&#x9009;&#x62E9;&#x4F60;&#x9700;&#x8981;&#x7684;&#x529F;&#x80FD;</li>
<li>&#x5B83;&#x53EF;&#x4EE5;&#x4E0D;&#x6C61;&#x67D3;&#x5168;&#x5C40;&#x7A7A;&#x95F4;</li>
<li>&#x5B83;&#x548C;babel&#x9AD8;&#x5EA6;&#x96C6;&#x6210;&#xFF0C;&#x53EF;&#x4EE5;&#x5BF9;core-js&#x7684;&#x5F15;&#x5165;&#x8FDB;&#x884C;&#x6700;&#x5927;&#x7A0B;&#x5EA6;&#x7684;&#x4F18;&#x5316;</li>
</ul>
<h5 id="&#x5347;&#x7EA7;core-js3&#x52A8;&#x673A;"><a name="&#x5347;&#x7EA7;core-js3&#x52A8;&#x673A;" class="anchor-navigation-ex-anchor" href="#&#x5347;&#x7EA7;core-js3&#x52A8;&#x673A;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x5347;&#x7EA7;core-js3&#x52A8;&#x673A;" class="plugin-anchor" href="#&#x5347;&#x7EA7;core-js3&#x52A8;&#x673A;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5347;&#x7EA7;core-js@3&#x52A8;&#x673A;</h5>
<p>&#x76EE;&#x524D;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x7684;&#x90FD;&#x9ED8;&#x8BA4;&#x662F;core-js@2&#xFF0C;&#x5B83;&#x5728; 2018&#x5E74; &#x4E4B;&#x524D;&#x5C31;&#x5C01;&#x9501;&#x4E86;&#x5206;&#x652F;&#xFF0C;&#x81F3;&#x6B64;&#x4E4B;&#x540E;&#x7684;&#x7279;&#x6027;&#x90FD;&#x53EA;&#x4F1A;&#x6DFB;&#x52A0;&#x5230;core-js@3&#xFF0C;&#x8FD9;&#x91CC;&#x6709;&#x4E00;&#x4E2A;&#x751F;&#x4EA7;&#x4F8B;&#x5B50;&#xFF0C;&#x4F7F;&#x7528;&#x4E86;core-js@2&#x4E0D;&#x652F;&#x6301;&#x7684;&#x65B0;&#x7279;&#x6027;&#xFF0C;&#x5BFC;&#x81F4;&#x9519;&#x8BEF;</p>
<ul>
<li>core-js@2&#x51FA;&#x73B0;&#x7684;&#x95EE;&#x9898;</li>
<li>Vue-cli&#x4F7F;&#x7528;flat&#x62A5;&#x9519;</li>
<li>vue-cli&#x4E5F;&#x4F1A;&#x5728;V4&#x5347;&#x7EA7;core-js</li>
<li>Roadmap for Vue-cli4</li>
<li>core-js@3&#x6DFB;&#x52A0;&#x7684;&#x7279;&#x6027;</li>
</ul>
<h5 id="core-js3-&#x7279;&#x6027;&#x6982;&#x89C8;"><a name="core-js3-&#x7279;&#x6027;&#x6982;&#x89C8;" class="anchor-navigation-ex-anchor" href="#core-js3-&#x7279;&#x6027;&#x6982;&#x89C8;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="core-js3-&#x7279;&#x6027;&#x6982;&#x89C8;" class="plugin-anchor" href="#core-js3-&#x7279;&#x6027;&#x6982;&#x89C8;"><i class="fa fa-link" aria-hidden="true"></i></a>core-js@3 &#x7279;&#x6027;&#x6982;&#x89C8;</h5>
<ul>
<li>&#x652F;&#x6301;ECMAScript&#x7A33;&#x5B9A;&#x529F;&#x80FD;&#xFF0C;&#x5F15;&#x5165;core-js@3&#x51BB;&#x7ED3;&#x671F;&#x95F4;&#x7684;&#x65B0;&#x529F;&#x80FD;&#xFF0C;&#x6BD4;&#x5982;flat</li>
<li>&#x52A0;&#x5165;&#x5230;ES2016-ES2019&#x4E2D;&#x7684;&#x63D0;&#x6848;&#xFF0C;&#x73B0;&#x5728;&#x5DF2;&#x7ECF;&#x88AB;&#x6807;&#x8BB0;&#x4E3A;&#x7A33;&#x5B9A;&#x529F;&#x80FD;</li>
<li>&#x66F4;&#x65B0;&#x4E86;&#x63D0;&#x6848;&#x7684;&#x5B9E;&#x73B0;&#xFF0C;&#x589E;&#x52A0;&#x4E86;proposals&#x914D;&#x7F6E;&#x9879;&#xFF0C;&#x7531;&#x4E8E;&#x63D0;&#x6848;&#x9636;&#x6BB5;&#x4E0D;&#x7A33;&#x5B9A;&#xFF0C;&#x9700;&#x8981;&#x8C28;&#x614E;&#x4F7F;&#x7528;</li>
<li>&#x589E;&#x52A0;&#x4E86;&#x5BF9;&#x4E00;&#x4E9B;web&#x6807;&#x51C6;&#x7684;&#x652F;&#x6301;&#xFF0C;&#x6BD4;&#x5982;URL &#x548C; URLSearchParams</li>
<li>&#x73B0;&#x5728;&#x652F;&#x6301;&#x539F;&#x578B;&#x65B9;&#x6CD5;&#xFF0C;&#x540C;&#x65F6;&#x4E0D;&#x6C61;&#x67D3;&#x539F;&#x578B;</li>
<li>&#x5220;&#x9664;&#x4E86;&#x8FC7;&#x65F6;&#x7684;&#x7279;&#x6027;</li>
</ul>
<h5 id="core-js3-&#x4E0E;-babel"><a name="core-js3-&#x4E0E;-babel" class="anchor-navigation-ex-anchor" href="#core-js3-&#x4E0E;-babel"><i class="fa fa-link" aria-hidden="true"></i></a><a name="core-js3-&#x4E0E;-babel" class="plugin-anchor" href="#core-js3-&#x4E0E;-babel"><i class="fa fa-link" aria-hidden="true"></i></a>core-js@3 &#x4E0E; babel</h5>
<p>&#x4EE5;&#x524D;&#x6211;&#x4EEC;&#x5B9E;&#x73B0;API&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F1A;&#x5F15;&#x5165;&#x6574;&#x4E2A;polyfill,&#x5176;&#x5B9E;polyfill&#x53EA;&#x662F;&#x5305;&#x62EC;&#x4E86;&#x4EE5;&#x4E0B;&#x4E24;&#x4E2A;&#x5305;</p>
<pre><code>core-js
regenerator-runtime
</code></pre><p>core-js@3 &#x5347;&#x7EA7;&#x4E4B;&#x540E;&#x5F03;&#x7528;&#x4E86;@babel/polyfill&#xFF0C;&#x4EE5;&#x4E0B;&#x662F;&#x7B49;&#x4EF7;&#x5B9E;&#x73B0;</p>
<pre><code class="lang-js"><span class="hljs-comment">// babel.config.js</span>
presets: [
  [<span class="hljs-string">&quot;@babel/preset-env&quot;</span>, {
    useBuiltIns: <span class="hljs-string">&quot;entry&quot;</span>, <span class="hljs-comment">// or &quot;usage&quot;&#xFF0C;&#x89C1;&#x5982;&#x4E0B;&#x8BF4;&#x660E;</span>
    corejs: <span class="hljs-number">3</span>,
  }]
]

<span class="hljs-comment">// &#x5982;&#x679C; useBuiltIns: &quot;entry&quot; &#x9700;&#x8981;&#x5728;&#x6253;&#x5305;&#x5165;&#x53E3;&#x6587;&#x4EF6;&#x5BFC;&#x5165;&#x4E24;&#x4E2A;&#x5305;&#xFF1A;</span>
<span class="hljs-keyword">import</span> <span class="hljs-string">&quot;core-js/stable&quot;</span>
<span class="hljs-keyword">import</span> <span class="hljs-string">&quot;regenerator-runtime/runtime&quot;</span>

<span class="hljs-comment">// &#x5982;&#x679C; useBuiltIns: &quot;usage&quot;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x5728;&#x5165;&#x53E3;&#x6587;&#x4EF6;&#x91CC;&#x5BFC;&#x5165;&#x5305;&#x4E86;</span>
</code></pre>
<h5 id="&#x603B;&#x7ED3;"><a name="&#x603B;&#x7ED3;" class="anchor-navigation-ex-anchor" href="#&#x603B;&#x7ED3;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x603B;&#x7ED3;" class="plugin-anchor" href="#&#x603B;&#x7ED3;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x603B;&#x7ED3;</h5>
<p>core-js@3 &#x5E9F;&#x5F03;&#x4E86; babel-polyfill&#xFF0C;&#x5B9E;&#x73B0;&#x4E86;&#x5B8C;&#x5168;&#x65E0;&#x6C61;&#x67D3;&#x7684;API&#x8F6C;&#x8BD1;&#xFF0C;&#x975E;&#x5E38;&#x6709;&#x6F5C;&#x529B;&#xFF0C;&#x4F46;&#x662F;&#x5176;&#x6682;&#x65F6;&#x4F1A;&#x589E;&#x52A0;&#x6253;&#x5305;&#x4F53;&#x79EF;&#xFF0C;&#x8FD9;&#x4E2A;&#x8FD8;&#x5F97;&#x770B;&#x672A;&#x6765;&#x666E;&#x53CA;&#x5EA6;&#x4E0A;&#x6765;&#x4E4B;&#x540E;&#x7684;&#x6743;&#x8861;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../" class="navigation navigation-prev " aria-label="Previous page: 前言">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="01-Webpack基础.html" class="navigation navigation-next " aria-label="Next page: 01-Webpack基础">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"基础","level":"1.2","depth":1,"next":{"title":"01-Webpack基础","level":"1.2.1","depth":2,"path":"basics/01-Webpack基础.md","ref":"./basics/01-Webpack基础.md","articles":[]},"previous":{"title":"前言","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-sharing","splitter","expandable-chapters-small","anchors","github","github-buttons","sharing-plus","anchor-navigation-ex","favicon","insert-logo"],"styles":{"website":"./styles/website.css"},"pluginsConfig":{"github":{"url":"https://github.com/lurongtao/felixbooks-electron"},"splitter":{},"search":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":false},"favicon":{"shortcut":"./source/images/favicon.jpg","bookmark":"./source/images/favicon.jpg","appleTouch":"./source/images/apple-touch-icon.jpg","appleTouchMore":{"120x120":"./source/images/apple-touch-icon.jpg","180x180":"./source/images/apple-touch-icon.jpg"}},"github-buttons":{"buttons":[{"user":"lurongtao","repo":"felixbooks-electron","type":"star","size":"small","count":true}]},"expandable-chapters-small":{},"sharing":{"qq":false,"all":["google","facebook","weibo","twitter","qq","qzone","linkedin","pocket"],"douban":false,"facebook":false,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{},"insert-logo":{"style":"background: skyblue; width: 100%; height: 100%;","url":"/felixbooks-electron/images/logo.png"}},"theme":"default","author":"古艺散人","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"千锋大前端小册-webpack","language":"zh-hans","links":{},"gitbook":"3.2.3","description":"webpack 入门与实战"},"file":{"path":"basics/01-Webpack基础.md","mtime":"2020-07-28T02:55:41.230Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-08-03T09:09:27.519Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-insert-logo/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

